package com.yanqu.road.server.cmd.chefduel.process2;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuel2;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CHEF_DUEL2_CAMP_RANK_REWARD, desc = "阵营排行奖励")
public class ChefDuel2CampGetRankRewardCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ChefDuelProto.ChefDuelGetCampRankRewardReqMsg reqMsg = ChefDuelProto.ChefDuelGetCampRankRewardReqMsg.parseFrom(packet.getBytes());
        ChefDuel2 chefDuel2 = ChefDuelMgr.getChefDuel2Map().get(reqMsg.getActivityId());
        if (chefDuel2 == null || !ActivityMgr.activityInShowTime(chefDuel2.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!ActivityMgr.activityInCanRewardPeriod(chefDuel2.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_IN_REWARD_SETTLEMENT_TIME;
            return;
        }
        if(!ActivityMgr.activityInCanRewardPeriod(chefDuel2.getActivityInfo())){
            ret = GameErrorCode.E_ACTIVITY_IN_REWARD_SETTLEMENT_TIME;
            return;
        }
        player.sendPacket(CrossProtocol.C_CHEF_DUEL2_CAMP_RANK_REWARD, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }

        ChefDuelProto.ChefDuelGetCampRankRewardRespMsg.Builder respMsg = ChefDuelProto.ChefDuelGetCampRankRewardRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_CHEF_DUEL2_CAMP_RANK_REWARD, respMsg);
    }
}
